<include file="../Public/admintop" />
<include file="../Public/adminleft" />
<tagLib name="html" />

<script language="javascript">
function ajaxFileUpload(fileToUpload,timestamp)
{
	
	$("#loading")
	.ajaxStart(function(){
		$(this).show();
	})
	.ajaxComplete(function(){
		$(this).hide();
	});

	$.ajaxFileUpload
	(
		{
			url:"{:U('Ad/upload')}",
			secureuri:false,
			fileElementId:fileToUpload,
			dataType: 'json',
			success: function (data, status)
			{
				
				if (status==1){
					$("#msg").text(data.info);
					
				}
				else{
					$("#msg").text(data.info);
					$('#imgbox').html("<img src=\"__ROOT__/"+data.data.savename+"\"/>");
					$("#imgbox").show();
					$("#fileToUpload_look_"+timestamp).preview();
					$("#img_url").val(data.data['savename']);
					
				}


			},
			error: function (data, status, e)
			{
				alert(e);
			}
		}
	)		
	return false;

}
$(function(){
	$('select[name=type] option').not(':last').click(function(){
		$('#type2').hide().empty();
	}).end().last().click(function(){
		$('#type2').append("添加:<input type=\"text\" name=\"type2\" value=\"\" />").show();
	});
	
});
</script>
<!-- Content (Right Column) -->
		<div id="content" class="box">

			<h1>修改广告</h1>
            <p class="msg info">提示：<label id="msg"></label></p>
            	
            <p id="btn-create" class="box">
              <a href="{:U('Ad/add')}">添加新广告</a>
            </p>
            <form action="{:U('Ad/Update')}" name="myform" method="post" enctype="multipart/form-data">
            <table class="nostyle" width="100%">
                    <tr>
						<td style="width:120px;">介绍:</td>
						<td><input type="text" size="40" name="remark" class="input-text" value="{$list.remark}" /></td>
					</tr>
                    <tr>
						<td style="width:120px;">连接:</td>
						<td><input type="text" size="40" name="link" class="input-text" value="{$list.link}" /></td>
					</tr>
                  <tr>
						<td style="width:120px;">类型:</td>
						<td><select name="type">
					         <option value="img">图片</option>
					         <option value="flash">flash</option>
					         <option value="code">代码</option>
					         <option value="html">自定义HTML</option>
					         <option value="link">链接</option>
					         <option value="txt">纯文本</option>
					         <iterate name="type" id="vo">
					          <option value="{$vo.type}">{$vo.type}</option>
					         </iterate>
					         <option value="">添加新类型</option>
					         </select> 
					         <span id="type2" style="display:none"></span>
					         </td>
					</tr> 
                    <tr>
						<td style="width:120px;">代码:</td>
						<td><textarea rows="5" cols="28" name="code">{$list.code}</textarea></td>
					</tr>
                    <tr>
						<td style="width:120px;">图片:</td>
						<td><input type="file" id="fileToUpload" name="fileToUpload" class="input-text" /><input class="input-submit" id="upload"  type="button" name="upload" value="上传" onClick="return ajaxFileUpload('fileToUpload','0');" /><notempty name="list['img_url']"><input type="button" onclick="window.location.href='{:U('Ad/setimg_empty',array('f'=>'img_url','id'=>$list['id']))}';" value="删除图片"/></notempty><br/>
						<span id="imgbox"><notempty name="list['img_url']">
		                    <img src="__ROOT__/{$list.img_url}" />
		                    </notempty></span>
						
						</td>
					</tr> 
                    <tr>
						<td style="width:120px;">文字:</td>
						<td><html:editor id="content" name="content" height="400x" width="100%" type="FCKeditor" content="{$list.content}" /></td>
					</tr> 
                    <tr>
						<td style="width:120px;">排序:</td>
						<td><input type="text"  size="40" name="sort" class="input-text" value="{$list.sort}" /></td>
					</tr>                     
                   
                    <tr>
						<td colspan="2" class="t-right"><input type="submit" class="input-submit" value="更新" />
                        </td>
					</tr>
            </table>
            <input type="hidden" name="img_url" id="img_url" value="{$list.img_url}" />
            <input type="hidden" name="id" id="id" value="{$list.id}" />
             <script language="javascript" type="text/javascript">
			   $("select[name='type'] option[value={$list['type']}]").attr("selected",true);
			</script>
        </form>
		</div> <!-- /content -->
<include file="../Public/adminfooter" />